//
//  OrderTableViewCell.m
//  LogisticsFollow
//
//  Created by JustFei on 2016/12/19.
//  Copyright © 2016年 manridy. All rights reserved.
//

#import "OrderTableViewCell.h"
#import "MBProgressHUD.h"

@interface OrderTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *orderNumber;
@property (weak, nonatomic) IBOutlet UILabel *customName;
@property (weak, nonatomic) IBOutlet UILabel *startPlace;
@property (weak, nonatomic) IBOutlet UILabel *endPlace;
@property (weak, nonatomic) IBOutlet UILabel *sendDate;
@property (weak, nonatomic) IBOutlet UILabel *receiveCompany;
@property (weak, nonatomic) IBOutlet UILabel *receivePeopleName;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumber;
@property (weak, nonatomic) IBOutlet UIButton *phoneButton;
@property (weak, nonatomic) IBOutlet UILabel *receivePlaceAddress;
@property (weak, nonatomic) IBOutlet UIView *PickUpView;
@property (weak, nonatomic) IBOutlet UILabel *PickUpAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *PickUpTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *AddressStateLabel;
@property (weak, nonatomic) IBOutlet UILabel *TimeStateLabel;

@property (nonatomic ,strong) MBProgressHUD *hud;
@end

@implementation OrderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//set model
- (void)setModel:(OrderResultModel *)model
{
    self.orderNumber.text = model.orderCode;
    self.customName.text = model.customerName;
    self.startPlace.text = model.startCity;
    self.endPlace.text = model.endCity;
    self.sendDate.text = model.fixedDate;
    self.receiveCompany.text = model.consigneeUnit;
    self.receivePeopleName.text = model.consignee;
    self.phoneNumber.text = model.telNumber;
    self.receivePlaceAddress.text = model.deliveryAddress;
    
    self.PickUpButton.layer.masksToBounds = YES;
    self.PickUpButton.layer.borderWidth = 1;
    self.PickUpButton.layer.cornerRadius = 2;
    
    switch (model.type) {
        case 1:
            [self.PickUpButton setTitle:@"提货" forState:UIControlStateNormal];
            break;
        case 2:
            [self.PickUpButton setTitle:@"干线" forState:UIControlStateNormal];
            break;
        case 3:
            [self.PickUpButton setTitle:@"配送" forState:UIControlStateNormal];
            break;
            
        default:
            break;
    }
    
    self.PickUpButton.layer.borderColor = kUIColorFromHEX(0xeb751d, 1).CGColor;
    self.PickUpButton.enabled = YES;
    
    switch (model.status) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            [self.PickUpButton setTitle:@"签收" forState:UIControlStateNormal];
        }
            break;
        case 2:
        {
            self.PickUpButton.hidden = YES;
        }
            
        default:
            break;
    }
    
    DLog(@"type == %d",model.type);
#if 0
    switch (model.type) {
        case 1:
        {
            CGRect rect = self.PickUpView.frame;
            rect.size.height = 1;
            self.PickUpView.frame = rect;
            [self.AddressStateLabel setText:@""];
            [self.TimeStateLabel setText:@""];
            [self.PickUpAddressLabel setText:@""];
            [self.PickUpTimeLabel setText:@""];
            //self.PickUpView.hidden = YES;
        }
            break;
        case 2:
            //提货cell
        {
            self.PickUpView.hidden = NO;
            self.AddressStateLabel.text = @"提货签到地点：";
            self.TimeStateLabel.text = @"提货签到时间：";
            self.PickUpAddressLabel.text = model.PickUpAddress;
            self.PickUpTimeLabel.text = model.PickUpTime;
        }
            break;
        case 3:
            //干线cell
        {
            self.PickUpView.hidden = NO;
            self.AddressStateLabel.text = @"干线签到地点：";
            self.TimeStateLabel.text = @"干线签到时间：";
            self.PickUpAddressLabel.text = model.MainAddress;
            self.PickUpTimeLabel.text = model.MainTime;
        }
            break;
        case 4:
            //签收cell
        {
            self.PickUpView.hidden = NO;
            self.AddressStateLabel.text = @"签收签到地点：";
            self.TimeStateLabel.text = @"签收签到时间：";
            self.PickUpAddressLabel.text = model.ReceiveAndSignAddress;
            self.PickUpTimeLabel.text = model.ReceiveAndSignTime;
        }
            break;
            
        default:
            break;
    }
#endif
}

#pragma mark - Action
- (IBAction)phoneAction:(UIButton *)sender
{
    UIWebView *callWebview =[[UIWebView alloc] init];
    NSURL *telURL =[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",self.phoneNumber.text]];// 貌似tel:// 或者 tel: 都行
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    
    //记得添加到view上
    [self addSubview:callWebview];
}

//提货Action
- (IBAction)PickUp:(UIButton *)sender
{
    if (![sender.titleLabel.text isEqualToString:@"签收"]) {
        if (self.startLocationBlock) {
            self.startLocationBlock();
//            if (result) {
//                
//            }
        }
    }else {
        if (self.endLocationBlock) {
            self.endLocationBlock();
        }
    }
}


@end
